x+1 is a list

Lets build graphs from functions. By graph, I don't mean graphic, by graph I mean the actual data structure.

For this purpose, imagine the following. I will grab a subset of a domain in R, namely D, for this subset I will create N equidistant samples, this samples are going to be the nodes of my graph. The nodes of my graph are going to be connected in the following way.

given f(x):DD with DD, we build a graph with an adjacency matrix defined by Aij the domain is divided in N intervals forming the enumerable finite set min(D)+ih | i[0,N1] and h:=max(D)min(D)N where each element is denoted by xi respectively the graph contains N nodes Aij=1argminL1(f(xi),xj)=j

  
    def build_domain(min_d: float, max_d: float, N: int): return np.linspace(min_d, max_d, N)

    def closest(fx, D: np.ndarray) -> int: return np.argmin(np.abs(fx-D))

    def build_graph(min_d: float, max_d: float, N: int, fn: Callable[[float], float]) -> nx.Graph:
        D = build_domain(min_d, max_d, N)
        G = nx.Graph()
        for i, x in enumerate(D): G.add_node(i, x=x)
        for i, x in enumerate(D):
            if i == N-1: break
            G.add_edge(i, closest(fn(x), D))
        return G
  

with this setting f(x)=x+1 gives birth to a list